var hzdr = {
    setBtnStatus: function () {
        var row = $('#grid_hzdr').datagrid('getSelected');

    }
}
var clickRowIndex = null;

$(function () {
    //加载企业机构
    $("#hzdr_gldw").gsjgqczcombobox();
    var sysDate = $("#hzdr_sysDate").val();
    //表格初始加载
    $('#grid_hzdr').datagrid({
        url: $.webPath() + "/cwgl/hzdr/hzdrList",
        toolbar: "#toolbar_hzdr",
        fitColumns: true,
        singleSelect: true,
        pagination: true,
        pageNumber: 1,
        fit: true,
        rownumbers: true,
        striped: true,
        columns: [
            [
                {field: 'bm', title: '单据号', width: 25, align: 'center'},
                {field: 'pjhm', title: '票据号码', width: 25, align: 'center'},
                {field: 'sfklx', title: '收款类型', width: 15,
                    formatter: function (value) {
                        if (value == '3')
                            return '销售收款';
                        else
                            return '供应退款';
                    }, align: 'center'
                },
                {field: 'gldw_qc', title: '关联企业', width: 40, align: 'center'},
                {field: 'sfje', title: '收款金额(元)', width: 25,
                    formatter: function (value) {
                        var sl = formatJe2(value, ",");
                        return sl;
                    },
                    styler: function () {
                        return 'color:green;font-size:14px;';
                    }, align: 'right'
                },
                {field: 'kxlx', title: '款项类型', width: 15,
                    formatter: function (value) {
                        if (value == '1')
                            return '预付款';
                        if (value == '2')
                            return '应付款';
                        if (value == '3')
                            return '预收款';
                        if (value == '4')
                            return '应收款';
                    }, align: 'center'
                },
                {field: 'khfksj', title: '客户付款时间', width: 20,
                    formatter: function (value) {
                        var val = formatDate(sysDate, value, 5);
                        return val
                    }, align: 'center'},
                {field: 'pjlx_z', title: '票据类型', width: 15, align: 'center'},
                {field: 'kxsy_z', title: '款项用途', width: 15, align: 'center'},
                {field: 'fkfs_z', title: '付款方式', width: 15, align: 'center'},
                {field: 'sbgs_jc', title: '申报公司', width: 30, align: 'center'},
                {field: 'sbr_xm', title: '申报人', width: 15, align: 'center'},
                {field: "bz", title: "备注", width: 20, align: 'center'},
                {field: "shrq", title: "审核日期", width: 20, align: 'center'} ,

                {field: "zt", title: "状态", width: 10,
                    formatter: function (value) {
                        if (value == 'ybc') {
                            return '已保存';
                        } else if (value == 'yrz') {
                            return '已入账';
                        } else if (value == 'ysh') {
                            return '已审核';
                        } else if (value == 'ytj') {
                            return '已提交';
                        } else if (value == 'ysd') {
                            return '已锁定';
                        } else if (value == 'yjs') {
                            return '已解锁';
                        } else if (value == 'yth') {
                            return '已退回';
                        }else if (value == 'ytz') {
                            return '已调整';
                        }
                    }, align: 'center'},
                   {field: 'sfhz', title: '是否划转', width: 15,
                 formatter: function (value) {
                 if (value == '0')
                 return '未划转';
                 if (value == '1')
                 return '已划转';

                 }, align: 'center'
                 },
                {field: 'insertFlag', title: '是否导入', width: 15,
                    formatter: function (value) {
                            if (value == 1)
                            return  '未导入';
                        else if (value ==2){
                            return  '导入开始';
                        }else if(value==3){
                            return '导入成功';
                        }
                    }, align: 'center'
                }

            ]
        ],
        onLoadSuccess: function () {
            var rows = $(this).datagrid("getRows");
            if (rows.length > 0) {
                $(this).datagrid("selectRow", 0);
                clickRowIndex = 0;
            }
            hzdr.setBtnStatus();
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        },
        onClickRow: function (rowIndex, rowData) {
            hzdr.setBtnStatus();
            if (clickRowIndex == rowIndex)
                return;
            clickRowIndex = rowIndex;
        },
        onSelect: function (rowIndex, rowData) {
            hzdr.setBtnStatus();
            if (clickRowIndex == rowIndex)
                return;
            clickRowIndex = rowIndex;
            hzdr.alwayShowDetail(rowData);
        }
    });
    //**********按钮触发事件**********

    //查询按钮
    $("#btn_hzdr_search").click(function () {
        hzdr_search();
    });

    //加载查询条件中的申报公司下拉框
    $("#hzdr_sbgs").combotree({
        loadFilter: function (rows) {
            return convert(rows);
        }
    });
});

//查询收款管理
function hzdr_search() {
    var sbgs = $('#hzdr_sbgs').combotree('getText') == null ? null : $('#hzdr_sbgs').combotree('getText');
    var sbgsId = $('#hzdr_sbgs').combotree('getValue') == null ? null : $('#hzdr_sbgs').combotree('getValue');
    //var zt = $('#hzdr_zt').combobox('getValue') == null ? null : $('#hzdr_zt').combobox('getValue');
    var skshStart = $('#hzdr_start').datebox('getValue');
    var skshEnd = $('#hzdr_end').datebox('getValue');
    $('#grid_hzdr').datagrid('load',
        {
            bm: $('#hzdr_bm').val(),
            sbgs: sbgs,
            sbgsId: sbgsId,
            gldwMc: $('#hzdr_gldw').attr("_text") == null ? null : $('#hzdr_gldw').attr("_text"),
            //  zt: zt,
            skr: $('#hzdr_zdr').val(),
            skshStart: skshStart,
            skshEnd: skshEnd
        }
    );
}

